//=============================================================================
// SentinelRocket
//=============================================================================
class SentinelRocket extends PepperPotRocket;

var int RealSpeed;

replication
{
    unreliable if(Role == Role_Authority)
        RealSpeed;
}

simulated function PostBeginPlay()
{
	super.PostBeginPlay();
	Velocity = RealSpeed * vector(Rotation);

}

simulated function ProcessTouch (Actor Other, Vector HitLocation)
{
    /*if(ShieldSphere(Other) != none)
    {
        log("hit1");
        if(ShieldSphere(Other).Shield != none)
        {
            log("hit2"@ShieldSphere(Other).Shield.Sentinel@owner);
            if(ShieldSphere(Other).Shield.Sentinel == sentinel(owner))
            {
                 log("hit3");
                 return;
            }
        }
    }
    if(Other == owner)
    {
        log("hit4");
        return;
    }*/
    //log("R-owner"@other@owner@instigator);
    if(owner==none && sentinel(owner)!=none)
        return;
	if((ShieldSphere(Other) != none && ShieldSphere(Other).Shield != none && ShieldSphere(Other).Shield.Sentinel == owner) || sentinel(Other) == owner)
		return;

	if(Other.IsA('BigShieldSphere') && BigShieldSphere(Other).Shield.PlayerReplicationInfo.Team.TeamIndex == pawn(owner).PlayerReplicationInfo.Team.TeamIndex)
		return;

    if(Other == Owner)
		return;

	Explode(HitLocation, normal(velocity));
}

simulated function BlowUp(vector HitLocation)
{
	HurtRadius(Damage, DamageRadius, MyDamageType, MomentumTransfer, HitLocation);
	MakeNoise(1.0);
}

//Sentinels don't damage their owner or themselves.
simulated function HurtRadius( float DamageAmount, float DamageRadius, class<DamageType> DamageType, float Momentum, vector HitLocation )
{
	local actor Victims;
	local float damageScale, dist;
	local vector dir;

	if( bHurtEntry )
		return;

	bHurtEntry = true;
	foreach VisibleCollidingActors( class 'Actor', Victims, DamageRadius, HitLocation )
	{
		// don't let blast damage affect fluid - VisibleCollisingActors doesn't really work for them - jag
		if(Victims != self && Victims.Role == ROLE_Authority && !Victims.IsA('FluidSurfaceInfo') && Victims != Owner)
		{
			dir = Victims.Location - HitLocation;
			dist = FMax(1,VSize(dir));
			dir = dir/dist;

			if(Instigator == None || Instigator.Controller == None)
				Victims.SetDelayedDamageInstigatorController(InstigatorController);

			if(Victims.IsA('ShieldSphere') && ShieldSphere(Victims).Shield.Sentinel == sentinel(owner))
				damageScale = 0;
			else
			    damageScale = 1 - FMax(0,(dist - Victims.CollisionRadius)/DamageRadius);

			Victims.TakeDamage
			(
				damageScale * DamageAmount,
				Instigator,
				Victims.Location - 0.5 * (Victims.CollisionHeight + Victims.CollisionRadius) * dir,
				(damageScale * Momentum * dir),
				DamageType
			);

			if (Vehicle(Victims) != None && Vehicle(Victims).Health > 0)
				Vehicle(Victims).DriverRadiusDamage(DamageAmount, DamageRadius, InstigatorController, DamageType, Momentum, HitLocation);
		}
	}

	bHurtEntry = false;
}

defaultproperties
{
     RealSpeed=300
     Speed=1700.000000
     MyDamageType=Class'taskforces.DamTypeSentinelRocket'
}
